package 创建者模式.原型模式.ps_DeepCopy;

import java.io.*;

/**
 * @Description TODO
 * @Author shallow
 * @Date 2023/3/4 12:38
 */

public class test {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Citation citation = new Citation();
        Student stu = new Student();
        stu.setName("张三");
        citation.setStu(stu);

        //深拷贝，使用对象输出流对象
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\JavaProject\\design_parttern\\a.txt"));
        oos.writeObject(citation);
        oos.close();
        //创建输入流对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\JavaProject\\design_parttern\\a.txt"));
        Citation clone = (Citation) ois.readObject();
        //释放资源
        ois.close();
        System.out.println(clone.getStu() == citation.getStu());

        clone.getStu().setName("pdd");
        citation.show();
        clone.show();

    }
}
